package com.xiaoyu.izf.model;

import cn.hutool.core.date.DateUtil;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "goods_info", schema = "izf", catalog = "")
public class GoodsInfo {
    private int id;
    private String title;
    private String thumb;
    private Integer price;
    private String detail;
    private Timestamp insertTime;
    private Timestamp updateTime;
    private Integer isDel;
    private String pageUrl;


    private String insertTimeStr;
    private String updateTimeStr;
    private Integer saleNum;
    private Integer viewPrice;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "thumb")
    public String getThumb() {
        return thumb;
    }

    public void setThumb(String thumb) {
        this.thumb = thumb;
    }

    @Basic
    @Column(name = "price")
    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    @Basic
    @Column(name = "detail")
    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    @Basic
    @Column(name = "insert_time")
    public Timestamp getInsertTime() {
        return insertTime;
    }

    public void setInsertTime(Timestamp insertTime) {
        this.insertTime = insertTime;
    }

    @Basic
    @Column(name = "update_time")
    public Timestamp getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }

    @Basic
    @Column(name = "is_del")
    public Integer getIsDel() {
        return isDel;
    }

    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }

    @Basic
    @Column(name = "page_url")
    public String getPageUrl() {
        return pageUrl;
    }

    public void setPageUrl(String pageUrl) {
        this.pageUrl = pageUrl;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GoodsInfo goodsInfo = (GoodsInfo) o;
        return id == goodsInfo.id &&
                Objects.equals(title, goodsInfo.title) &&
                Objects.equals(thumb, goodsInfo.thumb) &&
                Objects.equals(price, goodsInfo.price) &&
                Objects.equals(detail, goodsInfo.detail) &&
                Objects.equals(insertTime, goodsInfo.insertTime) &&
                Objects.equals(isDel, goodsInfo.isDel);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, title, thumb, price, detail, insertTime, isDel);
    }

    @Basic
    @Column(name = "sale_num")
    public Integer getSaleNum() {
        return saleNum;
    }

    public void setSaleNum(Integer saleNum) {
        this.saleNum = saleNum;
    }

    @Basic
    @Column(name = "view_price")
    public Integer getViewPrice() {
        return viewPrice;
    }

    public void setViewPrice(Integer viewPrice) {
        this.viewPrice = viewPrice;
    }

    @Transient
    public String getInsertTimeStr() {
        return DateUtil.formatDateTime(insertTime);
    }

    @Transient
    public String getUpdateTimeStr() {
        return DateUtil.formatDateTime(updateTime);
    }
}
